<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./OL_SDK/include-openlayers-local.js"></script>
  <script src="./libs/gaode.js"></script>
  <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
  <script src="./utils/setCanvasStyle.js"></script>
</head>

<body>
  <div id="map">
  </div>
  <script>
    var map = new ol.Map({
      target: "map",
      layers: [gaode],
      view: new ol.View({
        projection: 'EPSG:4326',
        center: [114.30, 30.50],
        zoom: 4
      })
    })
    let markerSource = new ol.source.Vector({

    })
    let markerLayer = new ol.layer.Vector({
      source: markerSource,
      zIndex: 1000,
      style: setCanvasStyle(map)
    })
    map.addLayer(markerLayer);
    /* IP定位获取当前城市geojson数据
    1、调用腾讯地图接口获取adcode邮编
    2、根据邮编调用阿里接口
 
     */
    // var url = `https://geo.datav.aliyun.com/areas_v3/bound/${adcode}.json`
    var qq_api = 'https://apis.map.qq.com/ws/location/v1/ip?key=5SHBZ-N3D3I-M4IGS-5Y7DV-RQXEQ-SRBNV&output=jsonp'
    $.ajax({
      url: qq_api,
      dataType: "jsonp",
      success: res => {
        let { lng, lat } = res.result.location;
        let { adcode } = res.result.ad_info
        /* 阿里geojson - url */
        let url = `https://geo.datav.aliyun.com/areas_v3/bound/${adcode}.json`
        let source = new ol.source.Vector({
          url,
          format: new ol.format.GeoJSON()
        })
        let layer = new ol.layer.Vector({
          source
        })
        map.addLayer(layer)
        /* 1、飞行到中心点 */
        let center = [lng, lat];
        console.log(center)
        map.getView().animate({
          center,
          zoom: 12,
          duration: 2000
        })
        /* 2、在中心点设置标注-canvas */
        let point = new ol.Feature({
          geometry: new ol.geom.Point(center)
        })
        markerSource.addFeature(point)
      }
    })
  </script>
</body>

</html>